package com.itheima.tlias84.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlias84.annotation.Log;
import com.itheima.tlias84.dto.SelectAllClazzDTO;
import com.itheima.tlias84.dto.SelectAllStudentsDTO;
import com.itheima.tlias84.dto.SelectStudentDTO;
import com.itheima.tlias84.mapper.StudentsMapper;
import com.itheima.tlias84.po.InsertStudentsParam;
import com.itheima.tlias84.po.SelectStudentsPageParam;
import com.itheima.tlias84.po.UpdateStudentParam;
import com.itheima.tlias84.po.ViolationParam;
import com.itheima.tlias84.service.StudentsService;
import com.itheima.tlias84.utils.ResultUtil;
import com.itheima.tlias84.vo.PageVO;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentsServiceImpl implements StudentsService{

    @Resource
    StudentsMapper studentsMapper;
    @Override
    public ResultUtil selectAllStudents(SelectStudentsPageParam param) {
        Page<Object> page = PageHelper.startPage(param.getPage(), param.getPageSize());
        List<SelectAllStudentsDTO> dtos = studentsMapper.selectAllStudents(param);
        PageVO<SelectAllStudentsDTO> pageVO = new PageVO<>();
        pageVO.setTotal(page.getTotal());
        pageVO.setRows(dtos);
        return ResultUtil.success(pageVO);
    }

    @Log
    @Override
    public int deleteById(List<Integer> ids) {
        return studentsMapper.deleteById(ids);
    }

    @Log
    @Override
    public int insertStudents(InsertStudentsParam param) {
        return studentsMapper.insertStudents(param);
    }

    @Override
    public SelectStudentDTO selectStudentById(Integer id) {
        return studentsMapper.selectStudentById(id);
    }

    @Log
    @Override
    public int updateStudent(UpdateStudentParam param) {
        return studentsMapper.updateStudent(param);
    }

    @Log
    @Override
    public int updateViolation(Integer id, Integer score) {
        return studentsMapper.updateViolation(id,score);
    }
}
